package org.yi.demo.annodemo.utils;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SessionUtils {
	
	public static SqlSessionFactory getSqlSessionFactory() throws IOException {
		String resource = "mybatis-config.xml";
		InputStream inputStream = Resources.getResourceAsStream(resource);
		return new SqlSessionFactoryBuilder().build(inputStream);
	}
	
	public static SqlSession getSession() throws IOException {
		return getSqlSessionFactory().openSession();
	}
	
	public static SqlSession getSession(boolean autoCommit) throws IOException {
		return getSqlSessionFactory().openSession(autoCommit);
	}

}
